#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>

#define SIZE 81
#define LIMIT 20
#define swap(type, a, b)    do {type c=a; a=b; b=c;} while(0)


char * s_gets(char *, int);
char * dispace(char *);
int move(char *, int, int, int);
void delspace(char *);

int main(void)
{
    char str[SIZE];

    printf("function trim my implements.\n");
    printf("enter empty line to quit!\n");

    while ((printf("enter string:\n"),  (s_gets(str, SIZE)) != NULL && *str != '\0')) {
        printf("\"%s\"\n", str);
        delspace(str);
        printf("\"%s\"\n", str);
    }

    puts("Bye!\n");

    return 0;
}

void delspace(char * str) {
    char *s = str;
    while (*str) {
        if (isgraph((unsigned char)*str))
            *s++ = *str;
        ++str;
    }
    *s='\0';
}

char * s_gets(char * str, int n)
{
    char * ret_val;

    ret_val = fgets(str, n, stdin);

    if (ret_val) {
        while (*str != '\n' && *str != '\0')
            ++str;
        if (*str == '\n')
            *str = '\0';
        else
            while (getchar() != '\n')
                ;
    }

    return ret_val;
}
